﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CosiNet.Conversions
{
    /// <summary>
    /// Class for providing methods to convert Byte Arrays to other objects
    /// </summary>
    public static class ByteArray
    {
        /// <summary>
        /// Convert Byte Array to ASCII String
        /// </summary>
        /// <param name="convert">The byte array to convert</param>
        /// <returns>A string with the content of the array as in ASCII encoding</returns>
        public static string ToString(byte[] convert)
        {
            string ret = "";
            for (int i = 0; i < convert.Length; i++)
            {
                ret += (char)convert[i];
            }
            return ret;
        }

        /// <summary>
        /// Adds byte array two to the end of byte array one.
        /// </summary>
        /// <param name="one"></param>
        /// <param name="two"></param>
        /// <returns></returns>
        public static byte[] JoinOn(byte[] one, byte[] two)
        {
            byte[] ret = new byte[(one.Length + two.Length)];
            for (int i = 0; i < one.Length; i++)
            {
                ret[i] = one[i];
            }
            for (int i = 0; i < two.Length; i++)
            {
                ret[(i + one.Length)] = two[i];
            }
            return ret;
        }
    }
}
